<link rel="stylesheet" href="/static/libs/editormd/css/editormd.min.css"/>

<!-- article 编辑界面-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>#(article.title)</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input name="id" disabled lay-verify="required" value="#(article.id)" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-inline">
            <input name="create_time" lay-verify="required" disabled
                   value="#date(article.create_time,'yyyy-MM-dd HH:mm:ss')" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
        <div class="layui-form-mid layui-word-aux">创建时间</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            #if("on".equals(article.is_open))
            <input name="is_open" type="checkbox" name="switch" lay-skin="switch" lay-text="启用|禁用" checked>
            #else
            <input name="is_open" type="checkbox" name="switch" lay-skin="switch" lay-text="启用|禁用">
            #end

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">精华置顶</label>
        <div class="layui-input-block">
            #if(article.is_quintessence ?? == 'on')
            <input name="is_quintessence" checked="" title="精华" type="checkbox">
            #else
            <input name="is_quintessence" title="精华" type="checkbox">
            #end

            #if(article.is_top ?? == 'on' )
            <input name="is_top" checked="" title="置顶" type="checkbox">
            #else
            <input name="is_top" title="置顶" type="checkbox">
            #end

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文章连接</label>
        <div class="layui-input-inline">
            <input name="url" lay-verify="required"
                   value="#(article.url)" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
        <div class="layui-form-mid layui-word-aux">填写文章自定义地址</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input name="title" lay-verify="required" value="#(article.title)" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-row layui-col-space15 layui-form-item layui-hide" id="LAY_quiz">
        <div class="layui-col-md3">
            <label class="layui-form-label">所属产品</label>
            <div class="layui-input-block">
                <select name="project">
                    <option></option>
                    <option value="layui">layui</option>
                    <option value="独立版layer">独立版layer</option>
                    <option value="独立版layDate">独立版layDate</option>
                    <option value="LayIM">LayIM</option>
                    <option value="Fly社区模板">Fly社区模板</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md3">
            <label class="layui-form-label" for="L_version">版本号</label>
            <div class="layui-input-block">
                <input type="text" id="L_version" value="" name="version" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label" for="L_browser">浏览器</label>
            <div class="layui-input-block">
                <input type="text" id="L_browser" value="" name="browser" placeholder="浏览器名称及版本，如：IE 11"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div id="editormd">
        <textarea name="content" style="display:none;">#(article.content)</textarea>
    </div>


    <div class="layui-form-item" style="text-align: center">
        <button class="layui-btn" lay-submit="" lay-filter="sendForm">确定修改</button>
    </div>


</form>

<script>
    layui.use(['element', 'form'], function () {
        var form = layui.form;


        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
        var parentIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引

        //监听提交
        form.on('submit(sendForm)', function (data) {

            console.log(JSON.stringify(data.field));
            layui.$.ajax({
                type: "post",
                contentType: "application/json;charset=utf-8", // 因为上面是JSON数据
                url: '/admin/article/edit',
                data: JSON.stringify(data.field),
                success: function (data) {

                    if (200 === data.code) {

                        //给父页面刷新
                        parent.layui.table.reload('table');
                        parent.layer.close(parentIndex);
                        parent.layer.msg('修改成功');

                    }

                    console.log(data);
                },
                error: function (data, textStatus, errorThrown) {
                    layer.msg("添加失败");
                    console.log(data);
                }
            });

            return false;
        });
    });
</script>


<script src="/static/libs/editormd/editormd.min.js"></script>
<script type="text/javascript">
    $(function () {
        var editor = editormd("editormd", {
            path: "/static/libs/editormd/lib/", // Autoload modules mode, codemirror, marked... dependents libs path
            height: 640,
            saveHTMLToTextarea: true,
            syncScrolling: "single",
        });

        /*
         // or
         var editor = editormd({
         id   : "editormd",
         path : "../lib/"
         });
         */
    });
</script>


